package cn.com.jinhao.provider.report.controller;

import cn.com.jinhao.hotline.commons.controller.BaseController;
import cn.com.jinhao.hotline.commons.util.RestResponse;
import cn.com.jinhao.provider.report.model.Statistics;
import cn.com.jinhao.provider.report.service.StatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * HotLine
 * <p>Description: 统计信息接口</p>
 *
 * @author ShaneMew
 * @version 1.0
 * @date 2019/10/29
 * @since 2019-10-29
 */

@RestController
@RequestMapping("reports")
@Api(tags = {"报表服务"})
public class StatisticsController extends BaseController {

    StatisticsService statisticsService;

    private final Log log = LogFactory.getLog(StatisticsController.class);

    @Autowired
    public StatisticsController(StatisticsService statisticsService) {
        this.statisticsService = statisticsService;
    }

    @ApiOperation(value = "统计查询", notes = "根据统计类别以及部门查询")
    @ApiImplicitParams
        ({
            @ApiImplicitParam(name = "reportType", value = "统计类别: 1-热线统计  2-委办局统计  3-事件紧急度统计  4-事件来源统计  5-事件大类统计  6-接线员统计", required = true, dataType = "String", defaultValue = "6"),
            @ApiImplicitParam(name = "deptCode", value = "部门编号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "beginDate", value = "开始时间", dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "String")
        })
    @GetMapping(value = {"/reportData"})
    public RestResponse<Object> getReport(@RequestParam(value = "reportType") String reportType, @RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "beginDate", required = false) String beginDate, @RequestParam(value = "endDate", required = false) String endDate) throws Exception {
        return new RestResponse<>(this.getData(reportType, beginDate, endDate, deptCode));
    }

    private Object getData(String type, String beginDate, String endDate, String deptCode) throws Exception {
        Statistics statistics = new Statistics();
        statistics.setDeptCode(deptCode);
        if (StringUtils.isNotBlank(beginDate)) {
            statistics.setBeginDate(beginDate);
        }
        if (StringUtils.isNotBlank(endDate)) {
            statistics.setEndDate(endDate);
        }
        Object result;
        switch (type) {
            case "1":
                result = statisticsService.hotlineReport(statistics).get("result");
                break;
            case "2":
                result = statisticsService.boardReport(statistics).get("result");
                break;
            case "3":
                result = statisticsService.urgeLevelReport(statistics).get("result");
                break;
            case "4":
                result = statisticsService.sourceReport(statistics).get("result");
                break;
            case "5":
                result = statisticsService.typeReport(statistics).get("result");
                break;
            default:
                result = statisticsService.operReport(statistics).get("result");
        }
        return result;
    }
}
